// 设置需要传递给接口的变量
let productid = location.href.split('?')[1].split('&')[0].split('=')[1]
// 设置span内容
let lastspan = document.querySelector('main .tip p .last')
$(lastspan).html(`${decodeURI(location.href).split('=')[2]}`)

$.ajax({
    method: 'get',
    async: 'false',
    url: `http://chst.vip:1234/api/getproduct?productid=${productid}`,
    success: function (res) {
        $('main section .top .title').text(res.result[0].productName)
        let imgSrc = res.result[0].productImg.match(/[0-9a-zA-Z:/._]+/g)[2]
        $('main section .top img').attr('src', imgSrc)
    }
})
$.ajax({
    method: 'get',
    async: 'false',
    url: `http://chst.vip:1234/api/getproductcom?productid=${productid}`,
    success: function (chat) {
        let liStr = ''
        chat.result.forEach(item => {
            liStr += ` <li>
                            <div class="topdiv">
                                <span>${item.comName}</span>
                                <span>${item.comTime}</span>
                            </div>
                            <div class="middlediv">
                                ${item.comContent}
                            </div>
                            <div class="bottomdiv">
                                ${item.comFrom}
                            </div>
                        </li>`
        });
        $('main section .bottom ul').html(liStr)
    }
})


let $span = $('main .tip p span')

$span.click(function () {
    if ($(this).html() === '首页&gt;') {
        location.href = `http://127.0.0.1:5500/domo/千锋商城项目/html/主页.html`
    } else if ($(this).html() === '全部分类&gt;') {
        location.href = `http://127.0.0.1:5500/domo/千锋商城项目/html/category.html`
    } 
})

toTop()

